﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DTO;

namespace QLTV
{
    public partial class frmTraCuuDocGia : Form
    {
        public frmTraCuuDocGia()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmTraCuuDocGia_Load(object sender, EventArgs e)
        {
            List<LoaiDocGiaDTO> listLoaiDG = new List<LoaiDocGiaDTO>();
            listLoaiDG = LoaiDocGiaService.LayDanhSachLoaiDocGia();
            cmbLoaiDocGia.DisplayMember = LoaiDocGiaColums.TenLoaiDocGia;
            cmbLoaiDocGia.ValueMember = LoaiDocGiaColums.MaLoaiDocGia;
            cmbLoaiDocGia.DataSource = listLoaiDG;

            txtHoTen.Enabled = false;
            cmbLoaiDocGia.Enabled = false;
        }

        private void checkHoTen_CheckedChanged(object sender, EventArgs e)
        {
            if (checkHoTen.Checked == true)
                txtHoTen.Enabled = true;
            else
                txtHoTen.Enabled = false;
        }

        private void checkLoaiDocGia_CheckedChanged(object sender, EventArgs e)
        {
            if (checkLoaiDocGia.Checked == true)
                cmbLoaiDocGia.Enabled = true;
            else
                cmbLoaiDocGia.Enabled = false;                    
        }

        private void btnTraCuu_Click(object sender, EventArgs e)
        {
            string hoTen = "";
            int maLoaiDG = 0;
            DataTable BangDocGia = new DataTable();

            if (checkHoTen.Checked == true)
                hoTen = txtHoTen.Text.Trim();
            if(checkLoaiDocGia.Checked==true)
                maLoaiDG=Convert.ToInt32 (cmbLoaiDocGia.SelectedValue);

            BangDocGia = DocGiaService.TraCuuDocGia(hoTen, maLoaiDG);
            dgvDanhSachDocGia.DataSource = BangDocGia;
        }             

        
    }
}
